package org.kailu.book.DAO;

import java.util.List;

import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.kailu.book.entity.ExportStationeryDetailsEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

@Repository
public class ExportStationeryDetailsDAO {

	@Autowired
	private SessionFactory sessionFactory;
	
	public void save(ExportStationeryDetailsEntity stationeryDetailsEntity) {
		this.sessionFactory.getCurrentSession().saveOrUpdate(stationeryDetailsEntity);
	}
	
	@SuppressWarnings("unchecked")
	public List<ExportStationeryDetailsEntity> getAll() {
		return this.sessionFactory.getCurrentSession().createCriteria(ExportStationeryDetailsEntity.class).list();
	}
	
	public ExportStationeryDetailsEntity get(int id) {
		return (ExportStationeryDetailsEntity) this.sessionFactory.getCurrentSession().get(ExportStationeryDetailsEntity.class, id);
	}
	
	@SuppressWarnings("unchecked")
	public List<ExportStationeryDetailsEntity> getByExportID(int export_id) {
		return this.sessionFactory.getCurrentSession().createCriteria(ExportStationeryDetailsEntity.class).add(Restrictions.eq("export.exportId", export_id)).list();
	}
	
	public void delete(int id) {
		ExportStationeryDetailsEntity stationeryDetailsEntity = (ExportStationeryDetailsEntity) this.sessionFactory.getCurrentSession().get(ExportStationeryDetailsEntity.class, id);
		
		if (stationeryDetailsEntity != null) {
			this.sessionFactory.getCurrentSession().delete(stationeryDetailsEntity);
		}
	}
}
